<template>
	<z-paging ref="paging" :auto-clean-list-when-reload="false" :auto-scroll-to-top-when-reload="false"
		v-model="dataList" @query="queryList"  :default-page-no="0" :default-page-size='10'>
		<template>
			<view class="">
				<!-- <view class="">
					<u-notice-bar :text="notice"></u-notice-bar>
				</view> -->
				<!--  -->
				<!-- <view class="topView">
					<swiper class="swiper" indicator-dots="true" autoplay="true" interval="3000" duration="500">
						<swiper-item v-for="(image, index) in bannerList" :key="index">
							<view @click="toTopDetils(index)" class="swiperItem">
								<image class="slide-image" :src="image"></image>
								<view class="seeBtn mainBgColor">
									点击查看
								</view>
							</view>

						</swiper-item>
					</swiper>
				</view> -->
			</view>

			<view class="" style=" background-color: white; padding: 10px; 20px; z-index: 100;position: sticky;top :0;">
				<!-- search -->
				<view @click="toSearchPage()" class="row-lineConter"
					style="margin: 10rpx 20rpx; height: 30rpx; border-radius: 20rpx; padding: 10px 15px; background-color: rgb(245, 245, 245);">
					<u-icon name="search"></u-icon>
					<view class="subTextColor" style="margin-left: 10rpx;">
						可搜索关键词，搜索资源名称
					</view>
				</view>
				<z-tabs :list="typeList" @change="change"></z-tabs>
			</view>
		</template>

		<view class="grid-list" style="padding: 0px 15px;">
			<view class="grid-item" @click="clickRow(index)" v-for="(item,index) in dataList" :key="index">
				<GridItemCell :dataModel="item"> </GridItemCell>
			</view>
		</view>

	</z-paging>
</template>


<script>
	// const db = uniCloud.database();
	import HomeCell from './home-cell.vue'
	import GridItemCell from './grid-item-cell.vue'

	export default {
		components: {
			HomeCell,
			GridItemCell
		},
		data() {
			return {
				notice: '升级成为会员送1000积分，发布群或名片用户面积分查看二维码，看广告双倍送积分。',
				dataList: [],
				// 轮播图数据，例如图片URL列表
				bannerList: [
					'https://mp-35bd1c1b-8095-44b6-b494-c65e6d85fd9c.cdn.bspapp.com/appConfigure/寄快递.jpg',
					'https://mp-35bd1c1b-8095-44b6-b494-c65e6d85fd9c.cdn.bspapp.com/appConfigure/寄快递2.jpg',
					'https://mp-35bd1c1b-8095-44b6-b494-c65e6d85fd9c.cdn.bspapp.com/appConfigure/群top1.jpg',
					'https://mp-35bd1c1b-8095-44b6-b494-c65e6d85fd9c.cdn.bspapp.com/appConfigure/分享页面推广图.jpg',
					// 更多图片URL
				],
				typeList: [],
				typeDataList: [],
				type: null,
				queryAll: "0",

			}
		},
		onLoad() {
			// uni.showLoading({
			// 	title:'数据加载中...'
			// })
			this.get_app_configure()

		},
		onShow() {
			console.log('保存过的id==', this.$idList);
			
		},

		methods: {
			get_app_configure() {
				// uni.showLoading({
				// 	title:'加载中...'
				// })
				// this.$uniCloudApi.get_app_configure().then(res => {
				// 	uni.hideLoading()
				// 	this.$setOpenAd(res.openAd)
				// 	this.$setVideoAdId(res.videoAdId);
				// }).catch(res => {
				// 	this.$showToast(res);
				// })
				this.$setOpenAd('0')
			},
			// @query所绑定的方法不要自己调用！！需要刷新列表数据时，只需要调用this.$refs.paging.reload()即可
			queryList(pageNo, pageSize) {
				if (this.type == null) {
					this.getTypeList().then(type => {
						this.type = type;
						this.$uniCloudApi.get_data_list(this.type, this.queryAll, pageNo, pageSize).then((res) => {
							this.$refs.paging.complete(res);
						}).catch(err => {
							this.$refs.paging.complete([]);
							this.errStr = err.toString();
							uni.showToast({
								title: err.toString(),
								icon: 'none'
							})
						})
					});
				} else {
					this.$uniCloudApi.get_data_list(this.type, this.queryAll, pageNo, pageSize).then((res) => {
						this.$refs.paging.complete(res);
					}).catch(err => {
						this.$refs.paging.complete([]);
						this.errStr = err.toString();
						uni.showToast({
							title: err.toString(),
							icon: 'none'
						})
					})
				}
			},
			getTypeList() {
				return new Promise((resolve, reject) => {
					var array = []
					this.$uniCloudApi.get_type_list().then(list => {
						this.typeDataList = list;
						list.forEach(item => {
							array.push(item.typeStr)
						})
						this.typeList = array;
						var model = this.typeDataList[0]
						this.queryAll = model.queryAll
						this.type = model.typeStr;
						resolve(this.type);
					}).catch(err => {});
				});

			},
			//点击切换类型
			change(index) {
				var item = this.typeDataList[index]
				console.log('点击==', index, '=', item)
				this.type = item.typeStr;
				this.queryAll = item.queryAll;
				this.$refs.paging.reload()
			},
			clickRow(index) {
				var model = this.dataList[index];
				uni.navigateTo({
					url: '../resource-details-page/resource-details-page?model=' + this.$encodeJson(model)
				});
				// if (this.$idList.includes(model._id)) {
				// 	uni.navigateTo({
				// 		url: '../result-page/result-page?model=' + this.$encodeJson(model)
				// 	});
				// } else {
				// 	uni.navigateTo({
				// 		url: '../resource-details-page/resource-details-page?model=' + this.$encodeJson(model)
				// 	});
				// }


			},

			toSearchPage() {
				uni.navigateTo({
					url: '../search-page/search-page?tableType=1'
				})
			},

			toTopDetils(index) {
				wx.navigateToMiniProgram({
					appId: 'wxdcd3d073e47d1742',
					path: '页面路径，如 "pages/index/index"',
					success: function(res) {
						console.log("跳转成功")
					},
					fail: function(err) {
						console.log("跳转失败", err)
					},
					complete: function() {
						console.log("跳转完成")
					}
				})
			}
		},
	
	onShareAppMessage(res) {
			var title = '免费资源【网盘链接驿站】影视！短剧！网剧！游戏！各类教程！各种资源应有尽有！快来领取吧。'
			let data = {
				title: title, //转发标题
				imageUrl: 'https://mp-35bd1c1b-8095-44b6-b494-c65e6d85fd9c.cdn.bspapp.com/appConfigure/资源分享图.jpg',
				success: function(res) {
					console.log('分享成功', res);
					uni.showToast({
						title: '分享成功'
					})
					// 分享成功的处理逻辑
				}
			}
			return data
		},
		onShareTimeline() {
			var title = '免费资源【网盘链接驿站】影视！短剧！网剧！游戏！各类教程！各种资源应有尽有！快来领取吧。'
			return {
				title: title,
				imageUrl: 'https://mp-35bd1c1b-8095-44b6-b494-c65e6d85fd9c.cdn.bspapp.com/appConfigure/资源分享图.jpg',
				success: function(res) {
					console.log('分享成功', res);
					// 分享成功的处理逻辑
				},
				fail: function(err) {
					console.error('分享失败', err);
					// 分享失败的处理逻辑
				},
				complete: function(res) {
					console.log('分享结束', res);
					// 分享结束的处理逻辑
				} //转发图片
			}
		}
	}
</script>


<style lang="scss" scoped>
	.topView {
		padding: 0px 15px;
		// border-radius: ;
	}

	.swiper {
		border-radius: 8px;
		overflow: hidden;
		width: 100%;
		height: 100px;
		/* 根据需要设置高度 */
	}

	.swiperItem {
		width: 100%;
		height: 100%;
		position: relative;
	}

	.slide-image {
		width: 100%;
		height: 100%;
	}

	.seeBtn {
		position: absolute;
		bottom: 30rpx;
		right: 20rpx;
		color: white;
		border-radius: 20rpx;
		// font-size: 24rpx;
		// border: 1px solid rgba(71, 120, 244, 1);
		padding: 6rpx 18rpx;
		box-shadow: 0rpx 0rpx 20rpx rgb(52, 116, 246);
	}

	.grid-list {
		display: flex;
		flex-wrap: wrap;
	}

	.grid-item {
		width: 50%;
		/* 每行三个，可根据需求调整 */
		display: flex;
		flex-direction: column;
		align-items: center;
	}
</style>